

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/fluid.png">
  <link rel="icon" href="/blog/images/base.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Airfe">
  <meta name="keywords" content="">
  
    <meta name="description" content="本文介绍了VueX相关知识。">
<meta property="og:type" content="article">
<meta property="og:title" content="VueX">
<meta property="og:url" content="https://airfe.gitee.io/blog/2023/06/23/VueX/index.html">
<meta property="og:site_name" content="Airfe的博客">
<meta property="og:description" content="本文介绍了VueX相关知识。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/VueX.png">
<meta property="article:published_time" content="2023-06-23T00:00:00.000Z">
<meta property="article:modified_time" content="2024-02-26T12:23:07.480Z">
<meta property="article:author" content="Airfe">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/VueX.png">
  
  
  
    <meta name="referrer" content="no-referrer" />
  
  <title>VueX - Airfe的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"airfe.gitee.io","root":"/blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"699a5d71ac7179b23874a59b0666a6f6","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","app_key":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":false}},"search_path":"/blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/blog/js/utils.js" ></script>
  <script  src="/blog/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?699a5d71ac7179b23874a59b0666a6f6";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  

  

  

  

  

  
    
  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/blog/">
      <strong>Airfe</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/blog/images/bg.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="VueX"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-06-23 08:00" pubdate>
          2023年06月23日
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          55 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">VueX</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="Vuex"><a href="#Vuex" class="headerlink" title="Vuex"></a>Vuex</h1><h2 id="概念理解"><a href="#概念理解" class="headerlink" title="概念理解"></a>概念理解</h2><p>Vuex是专门在Vue中实现集中式状态(数据)管理的一个Vue插件，对Vue应用中多个组件的共享状态进行集中式的管理(读&#x2F;写)也是一种组件间通信的方式，且适用于任意组件间通信。</p>
<p><img src="" srcset="/blog/img/loading.gif" lazyload data-original="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/markdown/image-20221022151715491.png" alt="image-20221022151715491"></p>
<ul>
<li>Actions(对象)：行为，当动作相关的值需要发送ajax请求才能获取的时候，才需要Actions</li>
<li>Mutations(对象)：修改加工</li>
<li>State(对象)：数据</li>
</ul>
<p>以上三个都是由<strong>store</strong>管理，相关api也是<strong>store</strong>身上的。</p>
<p>State里面存放数据，在Vue组件中欲修改这个数据，如果修改动作涉及到的数据还需要发送ajax请求调用dispatch()，由Action去拿到要操作的所有值，如果事先就明确值要如何修改不再牵扯到ajax请求，可以直接跳过Action，调用<strong>commit</strong>，交给<strong>Mutations做数据处理</strong>。</p>
<h2 id="使用场景"><a href="#使用场景" class="headerlink" title="使用场景"></a>使用场景</h2><ul>
<li>多个组件依赖于同一状态</li>
<li>来自不同组件的行为需要变更同一状态</li>
</ul>
<p>即<strong>共享</strong></p>
<h2 id="基础环境搭建"><a href="#基础环境搭建" class="headerlink" title="基础环境搭建"></a>基础环境搭建</h2><ol>
<li><p>下载安装<code>vuex</code> :<code>npm i vuex</code></p>
</li>
<li><p>创建<code>src/store/index.js </code>该文件需要<strong>引入并使用</strong>Vuex，创建Vuex中最为核心的<code>store</code></p>
<blockquote>
<p>要求Vue.use(Vuex)要在创建store实例之前使用，所以把Vue.use(Vuex) 放在暴露store的文件里</p>
</blockquote>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 引入Vue和Vuex</span><br><span class="hljs-keyword">import</span> Vue from <span class="hljs-string">&#x27;vue&#x27;</span><br><span class="hljs-keyword">import</span> Vuex from <span class="hljs-string">&#x27;vuex&#x27;</span><br><span class="hljs-comment">// 使用Vuex</span><br>Vue.use(Vuex) <br><span class="hljs-comment">//准备actions用于响应组件中的动作</span><br><span class="hljs-type">const</span> <span class="hljs-variable">actions</span> <span class="hljs-operator">=</span> &#123;&#125;<br><span class="hljs-comment">//准备mutations用于操作数据（state）</span><br><span class="hljs-type">const</span> <span class="hljs-variable">mutations</span> <span class="hljs-operator">=</span> &#123;&#125;<br><span class="hljs-comment">//准备state用于存储数据</span><br><span class="hljs-type">const</span> <span class="hljs-variable">state</span> <span class="hljs-operator">=</span> &#123;&#125;<br><br><span class="hljs-comment">//创建并暴露store</span><br>export <span class="hljs-keyword">default</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Vuex</span>.Store(&#123;<br>    actions,<br>    mutations,<br>    state<br>&#125;)<br></code></pre></td></tr></table></figure>

<ol start="3">
<li>在<code>src/main.js</code> 中创建<code>vm</code>时传入<code>store</code>配置项</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> Vue from <span class="hljs-string">&#x27;vue&#x27;</span><br><span class="hljs-keyword">import</span> App from <span class="hljs-string">&#x27;./App.vue&#x27;</span> <br><span class="hljs-keyword">import</span> store from <span class="hljs-string">&#x27;./store&#x27;</span> <span class="hljs-comment">//引入store</span><br>Vue.config.productionTip = <span class="hljs-literal">false</span><br><br><span class="hljs-keyword">new</span> <span class="hljs-title class_">Vue</span>(&#123;<br>  render: h =&gt; h(App),<br>  store<br>&#125;).$mount(<span class="hljs-string">&#x27;#app&#x27;</span>)<br></code></pre></td></tr></table></figure>

<h2 id="使用方法"><a href="#使用方法" class="headerlink" title="使用方法"></a>使用方法</h2><p>某组件从vuex读数据和改数据的案例</p>
<ol>
<li><p>在<strong>store.js</strong>中初始化数据<code>state</code></p>
</li>
<li><p>在组件中要处理数据的逻辑中，调用<code>dispatch</code>传递操作方法和数据，与之对应的<code>store.js</code>中的<code>actions</code>对象中定义这个函数</p>
</li>
<li><p>在<code>actions</code>中定义的函数中调用commit，与之对应的Mutations上也要有对应的函数进行处理逻辑</p>
<blockquote>
<p>组件中读取<code>vuex</code>中的数据<code>$store.state.数据</code></p>
<p>若组件中没有网络请求或其他业务逻辑，组件中也可越过<code>actions</code> ，即不写<code>dispatch</code> ，直接编写<code>commit</code></p>
</blockquote>
</li>
</ol>
<p><code>src/components/Count.vue</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//1.在组件中用$store调commit或dispatch方法，传函数名和参数</span><br>&lt;h1&gt;当前求和为：&#123;&#123;$store.state.sum &#125;&#125;&lt;/h1&gt; <br>methods:&#123;<br>    increment()&#123;<br>        <span class="hljs-built_in">this</span>.$store.commit(<span class="hljs-string">&#x27;JIA&#x27;</span>,<span class="hljs-built_in">this</span>.n)<br>    &#125;,<br>    decrement()&#123;<br>        <span class="hljs-built_in">this</span>.$store.commit(<span class="hljs-string">&#x27;JIAN&#x27;</span>,<span class="hljs-built_in">this</span>.n)<br>    &#125;,<br>    incrementOdd()&#123;<br>        <span class="hljs-built_in">this</span>.$store.dispatch(<span class="hljs-string">&#x27;jianOdd&#x27;</span>,<span class="hljs-built_in">this</span>.n)<br>    &#125;,<br>    incrementWait()&#123;<br>        <span class="hljs-built_in">this</span>.$store.dispatch(<span class="hljs-string">&#x27;jianWait&#x27;</span>, <span class="hljs-built_in">this</span>.n)<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><code>src/store/index.js </code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//引入Vue和Vuex</span><br><span class="hljs-keyword">import</span> Vue from <span class="hljs-string">&#x27;vue&#x27;</span><br><span class="hljs-keyword">import</span> Vuex from <span class="hljs-string">&#x27;vuex&#x27;</span><br><br><span class="hljs-comment">//使用Vuex插件</span><br>Vue.use(Vuex)<br>    <br><span class="hljs-comment">//准备actions用于响应组件中的动作（逻辑处理），context中有dispatch、commit、state等，是一个mini的$store</span><br><span class="hljs-type">const</span> <span class="hljs-variable">actions</span> <span class="hljs-operator">=</span> &#123;<br>    jianOdd(context, value) &#123;<br>        <span class="hljs-keyword">if</span> (context.state.sum % <span class="hljs-number">2</span>) &#123;<br>            context.commit(<span class="hljs-string">&#x27;JIA&#x27;</span>, value)<br>        &#125;<br>    &#125;,<br>    jianWait(context, value) &#123;<br>        setTimeout(() =&gt; &#123;<br>            context.commit(<span class="hljs-string">&#x27;JIA&#x27;</span>, value)<br>        &#125;, <span class="hljs-number">500</span>)<br>    &#125;<br>&#125;<br><span class="hljs-comment">// 准备mutations用于操作数据（state）</span><br><span class="hljs-type">const</span> <span class="hljs-variable">mutations</span> <span class="hljs-operator">=</span> &#123;<br>    JIA(state, value) &#123;<br>        state.sum += value<br>    &#125;,<br>    JIAN(state, value) &#123;<br>        state.sum -= value<br>    &#125;,<br>&#125;<br><span class="hljs-comment">// 1.准备state用于存储数据</span><br><span class="hljs-type">const</span> <span class="hljs-variable">state</span> <span class="hljs-operator">=</span> &#123;<br>    sum: <span class="hljs-number">0</span>  <span class="hljs-comment">//当前的和</span><br>&#125; <br><br><span class="hljs-comment">// 创建并暴露store</span><br>export <span class="hljs-keyword">default</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Vuex</span>.Store(&#123;<br>    actions,<br>    mutations,<br>    state,<br>&#125;)<br></code></pre></td></tr></table></figure>

<p>tips：组件中读取vuex中的数据: &#x3D;&#x3D;$store.state.sum&#x3D;&#x3D;   ;   组件中修改vuex中的数据：&#x3D;&#x3D;$store.dispatch(‘action中的方法名’，数据)&#x3D;&#x3D;，若是没有网络请求或其他的业务</p>
<p>逻辑，组件中也可以越过actions，直接使用&#x3D;&#x3D;$store.commit(‘mutations中的方法名’，数据)&#x3D;&#x3D;</p>
<h2 id="getters配置项"><a href="#getters配置项" class="headerlink" title="getters配置项"></a>getters配置项</h2><ol>
<li><p>概念：可以使用<code>getters </code>加工state，相当于写在store.js中的一个<code>全局计算属性</code>，可以通过$store.getters.bigSum拿到</p>
</li>
<li><p>配置和使用</p>
<blockquote>
<p>理解：state&#x3D;&gt;data    getters&#x3D;&gt;computed</p>
</blockquote>
</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">//1.store.js中配置</span><br><span class="hljs-comment">//准备getters用于state中的数据进行加工</span><br><span class="hljs-keyword">const</span> getters = &#123;<br>    <span class="hljs-title function_">bigSum</span>(<span class="hljs-params">state</span>) &#123;<br>        <span class="hljs-comment">//要写返回值</span><br>        <span class="hljs-keyword">return</span> state.<span class="hljs-property">sum</span> * <span class="hljs-number">10</span><br>    &#125;<br>&#125;<br><span class="hljs-comment">//创建并暴露store</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Vuex</span>.<span class="hljs-title class_">Store</span>(&#123;<br>    actions,<br>    mutations,<br>    state,<br>    getters<br>&#125;)<br><br><span class="hljs-comment">//2.组件中使用</span><br>&lt;h3&gt;当前求和放大十倍：&#123;&#123; $store.<span class="hljs-property">getters</span>.<span class="hljs-property">bigSum</span>&#125;&#125;&lt;/h3&gt;<br></code></pre></td></tr></table></figure>

<h2 id="四个map方法的使用"><a href="#四个map方法的使用" class="headerlink" title="四个map方法的使用"></a>四个map方法的使用</h2><p>为了避免一直写$store.state.数据拿数据的优化。</p>
<p><code>mapState</code>与<code>mapGetters</code>优化计算属性写法:</p>
<ol>
<li><code>mapState</code>方法：映射<code>state</code>中的数据为计算属性</li>
<li><code>mapGetters</code>方法: 映射<code>getters</code>中的数据为计算属性</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs java">&lt;script&gt;<br><span class="hljs-keyword">import</span> &#123;mapState&#125; from <span class="hljs-string">&#x27;vuex&#x27;</span><br>export <span class="hljs-keyword">default</span> &#123;<br>    computed:&#123;<br>        <span class="hljs-comment">//借助mapState生成计算属性，从state中读取数据。 (对象写法)</span><br>        ...mapState(&#123; he:<span class="hljs-string">&#x27;sum&#x27;</span>, xuexiao:<span class="hljs-string">&#x27;school&#x27;</span>, xueke:<span class="hljs-string">&#x27;subject&#x27;</span>&#125;),<br>        <span class="hljs-comment">//借助mapState生成计算属性，从state中读取数据。( 数组写法)</span><br>        ...mapState([<span class="hljs-string">&#x27;sum&#x27;</span>, <span class="hljs-string">&#x27;school&#x27;</span>, <span class="hljs-string">&#x27;subject&#x27;</span>]),<br><br>        <span class="hljs-comment">//借助mapGetters生成计算属性，从getters中读取数据。 (对象写法)</span><br>        ...mapGetters(&#123; bigSum:<span class="hljs-string">&#x27;bigSum&#x27;</span>&#125;),<br>        <span class="hljs-comment">//借助mapGetters生成计算属性，从getters中读取数据。( 数组写法)</span><br>        ...mapGetters([<span class="hljs-string">&#x27;bigSum&#x27;</span>])<br><br>        &#125;<br><br>    	等价于<br>        computed: &#123;<br>            he() &#123;<br>                <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.$store.state.sum<br>            &#125;,<br>            xuexiao() &#123;<br>                <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.$store.state.school<br>            &#125;,<br>            xueke() &#123;<br>                <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.$store.state.subject<br>            &#125;,<br>            bigSum() &#123;<br>                <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.$store.getters.bigSum<br>            &#125;    <br>        &#125;<br>&#125;<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p><code> mapMutations</code>与<code>mapActions</code>优化方法写法： </p>
<ol>
<li><p><code>mapMutations</code>方法：生成与<code>actions</code>对话的方法，即:包含<code>$store .dispatch(xxx)</code>的函数</p>
</li>
<li><p><code>mapActions</code>方法：生成与<code>mutations</code>对话的方法，即:包含<code>$store. commit(xxx)</code>的函数</p>
</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs react">&lt;button @click=&quot;increment(n)&quot;&gt;+&lt;/button&gt;<br>&lt;button @click=&quot;decrement(n)&quot;&gt;-&lt;/button&gt;<br>&lt;button @click=&quot;incrementOdd(n)&quot;&gt;当前求和为奇数再加&lt;/button&gt;<br>&lt;button @click=&quot;incrementWait(n)&quot;&gt;等一等再加&lt;/button&gt;<br><br>methods:&#123;<br>//借助mapMutations生成对应的方法，方法中会调用commit去联系mutations(对象写法)<br>. mapMutations (&#123;increment:&#x27;JIA&#x27;,decrement: &#x27;JIAN&#x27;&#125;),<br>//借助mapMutations生成对应的方法，方法中会调用commit去联系mutations (数组写法)<br>... mapMutations([&#x27;JIA&#x27;,&#x27;JIAN&#x27;]),<br>    <br>//借助mapActions生成对应的方法，方法中会调用dispatch去联系actions(对象写法)<br>...mapActions(&#123;incrementOdd:&#x27;jiaOdd&#x27;,incrementWait:&#x27;jiaWait&#x27;&#125;)<br>//借助mapActions生成对应的方法，方法中会调用dispatch去联系actions(数组写法)<br>...mapActions([&#x27;jiaOdd&#x27;,&#x27;jiaWait&#x27;])<br>        &#125;<br></code></pre></td></tr></table></figure>

<h2 id="Vuex模块化-namespace"><a href="#Vuex模块化-namespace" class="headerlink" title="Vuex模块化+namespace"></a>Vuex模块化+namespace</h2><p>目的是为了让代码更好维护</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">//1.在store.js中</span><br><span class="hljs-keyword">const</span> countAbout = &#123;<br>    <span class="hljs-attr">namespaced</span>:<span class="hljs-literal">true</span>,<span class="hljs-comment">//开启命名空间</span><br>    <span class="hljs-attr">state</span>:&#123;<span class="hljs-attr">x</span>:<span class="hljs-number">1</span>&#125;,<br>    <span class="hljs-attr">mutations</span>: &#123; ... &#125;,<br>    <span class="hljs-attr">actions</span>: &#123; ... &#125;,<br>    <span class="hljs-attr">getters</span>: &#123;<br>        <span class="hljs-title function_">bigSum</span>(<span class="hljs-params">state</span>)&#123;<br>            <span class="hljs-keyword">return</span> state.<span class="hljs-property">sum</span> * <span class="hljs-number">10</span><br>        &#125;<br>    &#125;<br>&#125;<br><span class="hljs-keyword">const</span> personAbout = &#123;<br>    <span class="hljs-attr">namespaced</span>:<span class="hljs-literal">true</span>,<span class="hljs-comment">//开启命名空间</span><br>    <span class="hljs-attr">state</span>:&#123; ... &#125;,<br>    <span class="hljs-attr">mutations</span>: &#123; .... &#125;,<br>    <span class="hljs-attr">actions</span>: &#123; ... &#125;,<br>    <span class="hljs-attr">getters</span>:&#123;<br>        <span class="hljs-title function_">firstPersonName</span>(<span class="hljs-params">state</span>)&#123;<br>            <span class="hljs-keyword">return</span> state.<span class="hljs-property">personList</span>[<span class="hljs-number">0</span>].<span class="hljs-property">name</span><br>        &#125;<br>    &#125;<br>&#125;<br><span class="hljs-keyword">const</span> store = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Vuex</span>.<span class="hljs-title class_">Store</span>(&#123;<br>    <span class="hljs-attr">modules</span>:&#123;<br>       countAbout,<br>       personAbout   <br>    &#125; <br>&#125;)<br><br><span class="hljs-comment">//2.组件中读取和修改数据</span><br><span class="hljs-comment">//读取state数据</span><br><span class="hljs-comment">//直接读取</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">$store</span>.<span class="hljs-property">state</span>.<span class="hljs-property">personAbout</span>.<span class="hljs-property">list</span><br><span class="hljs-comment">//借助mapState读取</span><br>...<span class="hljs-title function_">mapState</span>(<span class="hljs-string">&#x27;countAbout&#x27;</span>,[<span class="hljs-string">&#x27;sum&#x27;</span>,<span class="hljs-string">&#x27;school&#x27;</span>,<span class="hljs-string">&#x27;subject&#x27;</span>])<br><br><span class="hljs-comment">//读取getters数据</span><br><span class="hljs-comment">//直接读取</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">$store</span>.<span class="hljs-property">getters</span>[<span class="hljs-string">&#x27;personAbout/firstPersonName&#x27;</span>]<br><span class="hljs-comment">//借助mapGetters读取</span><br>...<span class="hljs-title function_">mapState</span>(<span class="hljs-string">&#x27;countAbout&#x27;</span>,[<span class="hljs-string">&#x27;bigSum&#x27;</span>])<br><br><span class="hljs-comment">//开启命名空间后，组件中调用dispatch</span><br><span class="hljs-comment">//直接dispatch</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">$store</span>.<span class="hljs-title function_">dispatch</span>(<span class="hljs-string">&#x27;personAbout/addPersonWang&#x27;</span>,person)<br><span class="hljs-comment">//借助mapActions:</span><br>...<span class="hljs-title function_">mapActions</span>(<span class="hljs-string">&#x27;countAbout&#x27;</span>,&#123;<span class="hljs-attr">incrementOdd</span>:<span class="hljs-string">&#x27;jiaOdd&#x27;</span>,<span class="hljs-attr">incrementWait</span>:<span class="hljs-string">&#x27;jiaWait&#x27;</span>&#125;)<br><br><span class="hljs-comment">//开启命名空间后，组件中调用commit</span><br><span class="hljs-comment">//直接commit</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">$store</span>.<span class="hljs-title function_">commit</span>(<span class="hljs-string">&#x27;personAbout/ADD_PERSON&#x27;</span>,person)<br><span class="hljs-comment">//借助mapMutations:</span><br>...<span class="hljs-title function_">mapActions</span>(<span class="hljs-string">&#x27;countAbout&#x27;</span>,&#123;<span class="hljs-attr">incrementOdd</span>:<span class="hljs-string">&#x27;JIA&#x27;</span>,<span class="hljs-attr">decrement</span>:<span class="hljs-string">&#x27;JIAN&#x27;</span>&#125;)<br></code></pre></td></tr></table></figure>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/" class="category-chain-item">前端技术栈</a>
  
  
    <span>></span>
    
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/%E6%A1%86%E6%9E%B6/" class="category-chain-item">框架</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/blog/tags/Vue/">#Vue</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>VueX</div>
      <div>https://airfe.gitee.io/blog/2023/06/23/VueX/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Airfe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年6月23日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/blog/2023/06/26/Vue%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/" title="Vue生命周期">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Vue生命周期</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/blog/2023/06/23/Vue%E8%B7%AF%E7%94%B1/" title="Vue-Router">
                        <span class="hidden-mobile">Vue-Router</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appKey":"P5fzMTGSJIoTaGvmgzsUHeNZ","path":"window.location.pathname","placeholder":"发表你的看法吧~","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false,"appid":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appkey":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com"},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
        <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数</span> <span id="times">载入时分秒</span> <script src="js/duration.js"></script> </div> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      蜀ICP备2023008943号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=https://beian.miit.gov.cn/"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="" srcset="/blog/img/loading.gif" lazyload data-original="/blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/events.js" ></script>
<script  src="/blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script defer src="/blog/js/leancloud.js" ></script>

  <script  src="/blog/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>

        <style>
            [bg-lazy] {
                background-image: none !important;
                background-color: #eee !important;
            }
        </style>
        <script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(r){r.imageLazyLoadSetting.processImages=t;var e=r.imageLazyLoadSetting.isSPA,n=r.imageLazyLoadSetting.preloadRatio||1,c=a();function a(){var t=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")),e=Array.prototype.slice.call(document.querySelectorAll("[bg-lazy]"));return t.concat(e)}function t(){e&&(c=a());for(var t,o=0;o<c.length;o++)0<=(t=(t=c[o]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(r.innerHeight*n||document.documentElement.clientHeight*n)&&function(){var t,e,n,a,i=c[o];e=function(){c=c.filter(function(t){return i!==t}),r.imageLazyLoadSetting.onImageLoaded&&r.imageLazyLoadSetting.onImageLoaded(i)},(t=i).hasAttribute("bg-lazy")?(t.removeAttribute("bg-lazy"),e&&e()):(n=new Image,a=t.getAttribute("data-original"),n.onload=function(){t.src=a,t.removeAttribute("data-original"),e&&e()},t.src!==a&&(n.src=a))}()}function i(){clearTimeout(t.tId),t.tId=setTimeout(t,500)}t(),document.addEventListener("scroll",i),r.addEventListener("resize",i),r.addEventListener("orientationchange",i)}(this);</script></body>
</html>
